using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace BookShop
{
	/// <summary>
	/// Strongly-typed collection for the Employee class.
	/// </summary>
    [Serializable]
	public partial class EmployeeCollection : ActiveList<Employee, EmployeeCollection>
	{	   
		public EmployeeCollection() {}
        
        /// <summary>
		/// Filters an existing collection based on the set criteria. This is an in-memory filter
		/// Thanks to developingchris for this!
        /// </summary>
        /// <returns>EmployeeCollection</returns>
		public EmployeeCollection Filter()
        {
            for (int i = this.Count - 1; i > -1; i--)
            {
                Employee o = this[i];
                foreach (SubSonic.Where w in this.wheres)
                {
                    bool remove = false;
                    System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
                    if (pi.CanRead)
                    {
                        object val = pi.GetValue(o, null);
                        switch (w.Comparison)
                        {
                            case SubSonic.Comparison.Equals:
                                if (!val.Equals(w.ParameterValue))
                                {
                                    remove = true;
                                }
                                break;
                        }
                    }
                    if (remove)
                    {
                        this.Remove(o);
                        break;
                    }
                }
            }
            return this;
        }
		
		
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the Employee table.
	/// </summary>
	[Serializable]
	public partial class Employee : ActiveRecord<Employee>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public Employee()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public Employee(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public Employee(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public Employee(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("Employee", TableType.Table, DataService.GetInstance("BookShop"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarEmployeeID = new TableSchema.TableColumn(schema);
				colvarEmployeeID.ColumnName = "EmployeeID";
				colvarEmployeeID.DataType = DbType.AnsiStringFixedLength;
				colvarEmployeeID.MaxLength = 10;
				colvarEmployeeID.AutoIncrement = false;
				colvarEmployeeID.IsNullable = false;
				colvarEmployeeID.IsPrimaryKey = true;
				colvarEmployeeID.IsForeignKey = false;
				colvarEmployeeID.IsReadOnly = false;
				colvarEmployeeID.DefaultSetting = @"";
				colvarEmployeeID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarEmployeeID);
				
				TableSchema.TableColumn colvarEmployeeName = new TableSchema.TableColumn(schema);
				colvarEmployeeName.ColumnName = "EmployeeName";
				colvarEmployeeName.DataType = DbType.AnsiString;
				colvarEmployeeName.MaxLength = 40;
				colvarEmployeeName.AutoIncrement = false;
				colvarEmployeeName.IsNullable = true;
				colvarEmployeeName.IsPrimaryKey = false;
				colvarEmployeeName.IsForeignKey = false;
				colvarEmployeeName.IsReadOnly = false;
				colvarEmployeeName.DefaultSetting = @"";
				colvarEmployeeName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarEmployeeName);
				
				TableSchema.TableColumn colvarSex = new TableSchema.TableColumn(schema);
				colvarSex.ColumnName = "Sex";
				colvarSex.DataType = DbType.Boolean;
				colvarSex.MaxLength = 0;
				colvarSex.AutoIncrement = false;
				colvarSex.IsNullable = true;
				colvarSex.IsPrimaryKey = false;
				colvarSex.IsForeignKey = false;
				colvarSex.IsReadOnly = false;
				colvarSex.DefaultSetting = @"";
				colvarSex.ForeignKeyTableName = "";
				schema.Columns.Add(colvarSex);
				
				TableSchema.TableColumn colvarStoreID = new TableSchema.TableColumn(schema);
				colvarStoreID.ColumnName = "StoreID";
				colvarStoreID.DataType = DbType.AnsiStringFixedLength;
				colvarStoreID.MaxLength = 10;
				colvarStoreID.AutoIncrement = false;
				colvarStoreID.IsNullable = true;
				colvarStoreID.IsPrimaryKey = false;
				colvarStoreID.IsForeignKey = false;
				colvarStoreID.IsReadOnly = false;
				colvarStoreID.DefaultSetting = @"";
				colvarStoreID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarStoreID);
				
				TableSchema.TableColumn colvarDepartmentID = new TableSchema.TableColumn(schema);
				colvarDepartmentID.ColumnName = "DepartmentID";
				colvarDepartmentID.DataType = DbType.AnsiString;
				colvarDepartmentID.MaxLength = 50;
				colvarDepartmentID.AutoIncrement = false;
				colvarDepartmentID.IsNullable = true;
				colvarDepartmentID.IsPrimaryKey = false;
				colvarDepartmentID.IsForeignKey = false;
				colvarDepartmentID.IsReadOnly = false;
				colvarDepartmentID.DefaultSetting = @"";
				colvarDepartmentID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDepartmentID);
				
				TableSchema.TableColumn colvarPosition = new TableSchema.TableColumn(schema);
				colvarPosition.ColumnName = "Position";
				colvarPosition.DataType = DbType.AnsiString;
				colvarPosition.MaxLength = 50;
				colvarPosition.AutoIncrement = false;
				colvarPosition.IsNullable = true;
				colvarPosition.IsPrimaryKey = false;
				colvarPosition.IsForeignKey = false;
				colvarPosition.IsReadOnly = false;
				colvarPosition.DefaultSetting = @"";
				colvarPosition.ForeignKeyTableName = "";
				schema.Columns.Add(colvarPosition);
				
				TableSchema.TableColumn colvarTitle = new TableSchema.TableColumn(schema);
				colvarTitle.ColumnName = "Title";
				colvarTitle.DataType = DbType.AnsiString;
				colvarTitle.MaxLength = 50;
				colvarTitle.AutoIncrement = false;
				colvarTitle.IsNullable = true;
				colvarTitle.IsPrimaryKey = false;
				colvarTitle.IsForeignKey = false;
				colvarTitle.IsReadOnly = false;
				colvarTitle.DefaultSetting = @"";
				colvarTitle.ForeignKeyTableName = "";
				schema.Columns.Add(colvarTitle);
				
				TableSchema.TableColumn colvarEmpGuid = new TableSchema.TableColumn(schema);
				colvarEmpGuid.ColumnName = "EmpGuid";
				colvarEmpGuid.DataType = DbType.Guid;
				colvarEmpGuid.MaxLength = 0;
				colvarEmpGuid.AutoIncrement = false;
				colvarEmpGuid.IsNullable = true;
				colvarEmpGuid.IsPrimaryKey = false;
				colvarEmpGuid.IsForeignKey = false;
				colvarEmpGuid.IsReadOnly = false;
				colvarEmpGuid.DefaultSetting = @"";
				colvarEmpGuid.ForeignKeyTableName = "";
				schema.Columns.Add(colvarEmpGuid);
				
				TableSchema.TableColumn colvarUserName = new TableSchema.TableColumn(schema);
				colvarUserName.ColumnName = "UserName";
				colvarUserName.DataType = DbType.String;
				colvarUserName.MaxLength = 50;
				colvarUserName.AutoIncrement = false;
				colvarUserName.IsNullable = true;
				colvarUserName.IsPrimaryKey = false;
				colvarUserName.IsForeignKey = false;
				colvarUserName.IsReadOnly = false;
				colvarUserName.DefaultSetting = @"";
				colvarUserName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarUserName);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["BookShop"].AddSchema("Employee",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("EmployeeID")]
		[Bindable(true)]
		public string EmployeeID 
		{
			get { return GetColumnValue<string>(Columns.EmployeeID); }
			set { SetColumnValue(Columns.EmployeeID, value); }
		}
		  
		[XmlAttribute("EmployeeName")]
		[Bindable(true)]
		public string EmployeeName 
		{
			get { return GetColumnValue<string>(Columns.EmployeeName); }
			set { SetColumnValue(Columns.EmployeeName, value); }
		}
		  
		[XmlAttribute("Sex")]
		[Bindable(true)]
		public bool? Sex 
		{
			get { return GetColumnValue<bool?>(Columns.Sex); }
			set { SetColumnValue(Columns.Sex, value); }
		}
		  
		[XmlAttribute("StoreID")]
		[Bindable(true)]
		public string StoreID 
		{
			get { return GetColumnValue<string>(Columns.StoreID); }
			set { SetColumnValue(Columns.StoreID, value); }
		}
		  
		[XmlAttribute("DepartmentID")]
		[Bindable(true)]
		public string DepartmentID 
		{
			get { return GetColumnValue<string>(Columns.DepartmentID); }
			set { SetColumnValue(Columns.DepartmentID, value); }
		}
		  
		[XmlAttribute("Position")]
		[Bindable(true)]
		public string Position 
		{
			get { return GetColumnValue<string>(Columns.Position); }
			set { SetColumnValue(Columns.Position, value); }
		}
		  
		[XmlAttribute("Title")]
		[Bindable(true)]
		public string Title 
		{
			get { return GetColumnValue<string>(Columns.Title); }
			set { SetColumnValue(Columns.Title, value); }
		}
		  
		[XmlAttribute("EmpGuid")]
		[Bindable(true)]
		public Guid? EmpGuid 
		{
			get { return GetColumnValue<Guid?>(Columns.EmpGuid); }
			set { SetColumnValue(Columns.EmpGuid, value); }
		}
		  
		[XmlAttribute("UserName")]
		[Bindable(true)]
		public string UserName 
		{
			get { return GetColumnValue<string>(Columns.UserName); }
			set { SetColumnValue(Columns.UserName, value); }
		}
		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(string varEmployeeID,string varEmployeeName,bool? varSex,string varStoreID,string varDepartmentID,string varPosition,string varTitle,Guid? varEmpGuid,string varUserName)
		{
			Employee item = new Employee();
			
			item.EmployeeID = varEmployeeID;
			
			item.EmployeeName = varEmployeeName;
			
			item.Sex = varSex;
			
			item.StoreID = varStoreID;
			
			item.DepartmentID = varDepartmentID;
			
			item.Position = varPosition;
			
			item.Title = varTitle;
			
			item.EmpGuid = varEmpGuid;
			
			item.UserName = varUserName;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(string varEmployeeID,string varEmployeeName,bool? varSex,string varStoreID,string varDepartmentID,string varPosition,string varTitle,Guid? varEmpGuid,string varUserName)
		{
			Employee item = new Employee();
			
				item.EmployeeID = varEmployeeID;
			
				item.EmployeeName = varEmployeeName;
			
				item.Sex = varSex;
			
				item.StoreID = varStoreID;
			
				item.DepartmentID = varDepartmentID;
			
				item.Position = varPosition;
			
				item.Title = varTitle;
			
				item.EmpGuid = varEmpGuid;
			
				item.UserName = varUserName;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn EmployeeIDColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn EmployeeNameColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn SexColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn StoreIDColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn DepartmentIDColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        public static TableSchema.TableColumn PositionColumn
        {
            get { return Schema.Columns[5]; }
        }
        
        
        
        public static TableSchema.TableColumn TitleColumn
        {
            get { return Schema.Columns[6]; }
        }
        
        
        
        public static TableSchema.TableColumn EmpGuidColumn
        {
            get { return Schema.Columns[7]; }
        }
        
        
        
        public static TableSchema.TableColumn UserNameColumn
        {
            get { return Schema.Columns[8]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string EmployeeID = @"EmployeeID";
			 public static string EmployeeName = @"EmployeeName";
			 public static string Sex = @"Sex";
			 public static string StoreID = @"StoreID";
			 public static string DepartmentID = @"DepartmentID";
			 public static string Position = @"Position";
			 public static string Title = @"Title";
			 public static string EmpGuid = @"EmpGuid";
			 public static string UserName = @"UserName";
						
		}
		#endregion
		
		#region Update PK Collections
		
        #endregion
    
        #region Deep Save
		
        #endregion
	}
}
